home *** CD-ROM | disk | FTP | other *** search
/ Aminet 22 / Aminet 22 (1997)(GTI - Schatztruhe)[!][Dec 1997].iso / Aminet / dev / src / ConfigFileSrc.lha / ConfigFileSrc12 / Library / Funcs / Get.c < prev    next >
Encoding:
Text File  |  1997-10-02  |  5.8 KB  |  234 lines

  1. /*
  2. **        $PROJECT: ConfigFile.library
  3. **        $FILE: Get.c
  4. **        $DESCRIPTION: cf_Get#?() functions
  5. **
  6. **        (C) Copyright 1996-1997 Marcel Karas
  7. **             All Rights Reserved.
  8. */
  9.  
  10. /****** configfile.library/cf_GetItem ****************************************
  11. *
  12. *   NAME
  13. *        cf_GetItem -- Get the contents of an item node or the default.
  14. *
  15. *   SYNOPSIS
  16. *        Contents = cf_GetItem(ItemNode,Type,Default);
  17. *        D0                    A0       D0   D1
  18. *
  19. *        LONG cf_GetItem(CFItem *,ULONG,LONG);
  20. *
  21. *   FUNCTION
  22. *        This function gets the contents of an item node. If Type not equal
  23. *        with the type of the item node the functions return the default.
  24. *
  25. *   INPUTS
  26. *        ItemNode - The item node.
  27. *        Type - Contents type (see cf_NewItem()).
  28. *        Default - Default contents.
  29. *
  30. *   RESULT
  31. *        Contents - The contents of the item node or the default.
  32. *
  33. *   SEE ALSO
  34. *        cf_GetItemNum()
  35. *
  36. ******************************************************************************
  37. *
  38. */
  39.  
  40. SLibCall LONG cf_GetItem ( REGA0 iCFItem * ItemNode , REGD0 ULONG Type , REGD1 LONG Default )
  41. {
  42.     FuncDe(bug("cf_GetItem($%08lx,%ld,[$%08lx,%ld])\n{\n", ItemNode, Type,
  43.             Default, Default));
  44.  
  45.     FuncDe(bug("   return($%08lx)\n}\n", ( ItemNode->Type == Type )
  46.             ? ItemNode->Contents.Number : Default ));
  47.  
  48.     return (( ItemNode->Type == Type ) ? ItemNode->Contents.Number : Default);
  49. }
  50.  
  51. /****** configfile.library/cf_GetItemNum *************************************
  52. *
  53. *   NAME
  54. *        cf_GetItemNum -- Get the contents of an item node or the default.
  55. *
  56. *   SYNOPSIS
  57. *        Contents = cf_GetItemNum(ArgNode,Position,Type,Default);
  58. *        D0                       A0      D0       D1   D2
  59. *
  60. *        LONG cf_GetItemNum(CFArgument *,ULONG,ULONG,LONG);
  61. *
  62. *   FUNCTION
  63. *        This function gets the contents of an item node from the specific
  64. *        position. If Type not equal with the type of the item node the
  65. *        function returns the default.
  66. *
  67. *   INPUTS
  68. *        ArgNode - The argument node.
  69. *        Position - Position of the item node (from 1 to X).
  70. *        Type - Contents type (see cf_NewItem()).
  71. *        Default - Default contents.
  72. *
  73. *   RESULT
  74. *        Contents - The contents of the item node or the default.
  75. *
  76. *   SEE ALSO
  77. *        cf_GetItem()
  78. *
  79. ******************************************************************************
  80. *
  81. */
  82.  
  83. SLibCall LONG cf_GetItemNum ( REGA0 iCFArgument * ArgNode ,
  84.                 REGD0 ULONG Position , REGD1 ULONG Type , REGD2 LONG Default )
  85. {
  86.     iCFItem * ItemNode;
  87.     ULONG ActualPosition=0;
  88.  
  89.     FuncDe(bug("cf_GetItemNum($%08lx,%ld,%ld,[$%08lx,%ld])\n{\n", ArgNode, Position,
  90.             Type, Default, Default));
  91.  
  92.     if ( ItemNode = cf_LockItemList (ArgNode) )
  93.     {
  94.         while ( ItemNode = cf_NextItem (ItemNode) )
  95.         {
  96.             ActualPosition++;
  97.             if ( ActualPosition == Position )
  98.             {
  99.                 if ( ItemNode->Type == Type ) return (ItemNode->Contents.Number);
  100.                 else
  101.                 {
  102.                     FuncDe(bug("   return($%08lx)\n}\n", Default));
  103.                     return (Default);
  104.                 }
  105.             }
  106.         }
  107.         
  108.         cf_UnlockItemList (ArgNode);
  109.     }
  110.  
  111.     FuncDe(bug("   return($%08lx)\n}\n", Default));
  112.     return (Default);
  113. }
  114.  
  115. /****** configfile.library/cf_GetItemType ************************************
  116. *
  117. *   NAME
  118. *        cf_GetItemType -- Get the type of an item node. (V2)
  119. *
  120. *   SYNOPSIS
  121. *        Type = cf_GetItemType(ItemNode);
  122. *        D0                    A0
  123. *
  124. *        UBYTE cf_GetItemType(CFItem *);
  125. *
  126. *   FUNCTION
  127. *        This function returns the contents type of an item node.
  128. *
  129. *   INPUTS
  130. *        ItemNode - The item node.
  131. *
  132. *   RESULT
  133. *        Type - Contents type (see cf_NewItem()).
  134. *
  135. *   SEE ALSO
  136. *        cf_GetItemSType(), cf_NewItem()
  137. *
  138. ******************************************************************************
  139. *
  140. */
  141.  
  142. SLibCall UBYTE cf_GetItemType ( REGA0 iCFItem * ItemNode )
  143. {
  144.     FuncDe(bug("cf_GetItemType($%08lx)\n{\n   return(%ld)\n}\n",
  145.             ItemNode, ItemNode->Type));
  146.  
  147.     return (ItemNode->Type);
  148. }
  149.  
  150. /****** configfile.library/cf_GetItemSType ***********************************
  151. *
  152. *   NAME
  153. *        cf_GetItemSType -- Get the special type of an item node. (V2)
  154. *
  155. *   SYNOPSIS
  156. *        SpecialType = cf_GetItemSType(ItemNode);
  157. *        D0                            A0
  158. *
  159. *        UBYTE cf_GetItemSType(CFItem *);
  160. *
  161. *   FUNCTION
  162. *        This function returns the special type of an item node.
  163. *
  164. *   INPUTS
  165. *        ItemNode - The item node.
  166. *
  167. *   RESULT
  168. *        SpecialType - Special type (see cf_NewItem()).
  169. *
  170. *   SEE ALSO
  171. *        cf_GetItemType(), cf_NewItem()
  172. *
  173. ******************************************************************************
  174. *
  175. */
  176.  
  177. SLibCall UBYTE cf_GetItemSType ( REGA0 iCFItem * ItemNode )
  178. {
  179.     FuncDe(bug("cf_GetItemSType($%08lx)\n{\n   return(%ld)\n}\n",
  180.             ItemNode, ItemNode->SpecialType));
  181.  
  182.     return (ItemNode->SpecialType);
  183. }
  184.  
  185. /****** configfile.library/cf_GetItemOnly ************************************
  186. *
  187. *   NAME
  188. *        cf_GetItemOnly -- Get the contents of an item node. (V2)
  189. *
  190. *   SYNOPSIS
  191. *        Contents = cf_GetItemOnly(ItemNode);
  192. *        D0                        A0
  193. *
  194. *        LONG cf_GetItemOnly(CFItem *);
  195. *
  196. *   FUNCTION
  197. *        This function gets the contents of an item node.
  198. *
  199. *   INPUTS
  200. *        ItemNode - The item node.
  201. *
  202. *   RESULT
  203. *        Contents - The Contents of the item node.
  204. *
  205. *   EXAMPLE
  206. *        CFItem  * myItemNode;
  207. *        LONG      Contents;
  208. *
  209. *        ...
  210. *        Contents = cf_GetItemOnly (myItemNode);
  211. *
  212. *        printf ("The contents of the item node is ");
  213. *
  214. *        if ( cf_GetItemType (myItemNode) == CF_ITYP_STRING )
  215. *           printf ("'%s'\n", Contents);
  216. *        else
  217. *           printf ("%ld\n", Contents);
  218. *        ...
  219. *
  220. *   SEE ALSO
  221. *        cf_GetItemNum(), cf_GetItem()
  222. *
  223. ******************************************************************************
  224. *
  225. */
  226.  
  227. SLibCall LONG cf_GetItemOnly ( REGA0 iCFItem * ItemNode )
  228. {
  229.     FuncDe(bug("cf_GetItemOnly($%08lx)\n{\n   return([$%08lx,%ld])\n}\n",
  230.             ItemNode, ItemNode->Contents.Number, ItemNode->Contents.Number));
  231.  
  232.     return (ItemNode->Contents.Number);
  233. }
  234.